// components/unit-picker/unit-picker.js
Component({
  options: {
    addGlobalClass: true,
  },
  properties: {
    // 组件属性
    units: {
      type: Array,
      value: []
    },
    selectedIndex: {
      type: Number,
      value: 0
    },
    placeholder: {
      type: String,
      value: '请选择单位'
    }
  },
  data: {
    // 组件数据
  },
  methods: {
    // 组件方法
    onUnitChange: function (e) {
      const selectedIndex = e.detail.value;
      const selectedUnit = this.data.units[selectedIndex];
      
      this.setData({
        selectedIndex: selectedIndex
      });
      
      // 触发自定义事件
      this.triggerEvent('change', {
        selectedIndex: selectedIndex,
        selectedUnit: selectedUnit
      });
    }
  }
});